package com.hzw.saas.api.property.enmus;

import java.util.Objects;

import cn.hutool.core.lang.Assert;

/**
 * 系统参数key
 *
 * @author zzl
 * @since 09/13/2021
 */
public enum SysParamKeyEnum {

    APP_BACKEND_HOST(SysParamModuleEnum.HOST.getModule(), "appBackendHost", "app后端host"),
    APP_FRONTEND_HOST(SysParamModuleEnum.HOST.getModule(), "appFrontendHost", "app前端host"),
    ADMIN_BACKEND_HOST(SysParamModuleEnum.HOST.getModule(), "adminBackendHost", "admin后端host"),
    ADMIN_FRONTEND_HOST(SysParamModuleEnum.HOST.getModule(), "adminFrontendHost", "admin前端host"),
    IGNORE_AUTH_URLS(SysParamModuleEnum.HOST.getModule(), "ignoreAuthUrls", "忽略登录认证的URL列表"),
    OUTPUT_TRACK(SysParamModuleEnum.EXCEPTION.getModule(), "outputTrack", "是否将异常堆栈输出到前端"),
    OUTPUT_MSG(SysParamModuleEnum.EXCEPTION.getModule(), "outputMsg", "不输出异常信息时，返回的错误信息"),
    SUPER_ADMIN_MODE(SysParamModuleEnum.RBAC.getModule(), "superAdminMode", "是否启用超级管理员"),
    SUPER_ADMIN_ID(SysParamModuleEnum.RBAC.getModule(), "superAdminId", "超级管理员ID"),
    SMS_TEST(SysParamModuleEnum.SMS.getModule(), "test", "开启短信测试,false或不配置则使用真实短信发送"),
    EMAIL_TEST(SysParamModuleEnum.EMAIL.getModule(), "test", "开启邮件测试,false或不配置则使用真实邮箱发送"),
    EMAIL_HOST(SysParamModuleEnum.EMAIL.getModule(), "host", "邮件发送服务器地址"),
    EMAIL_PORT(SysParamModuleEnum.EMAIL.getModule(), "port", "邮件发送服务器端口"),
    EMAIL_FROM(SysParamModuleEnum.EMAIL.getModule(), "from", "发件人邮箱"),
    EMAIL_USER(SysParamModuleEnum.EMAIL.getModule(), "user", "发件人用户名"),
    EMAIL_PASS(SysParamModuleEnum.EMAIL.getModule(), "pass", "发件人邮箱密码(授权码)"),
    EMAIL_AUTH(SysParamModuleEnum.EMAIL.getModule(), "auth", "是否需要用户名密码验证"),
    EMAIL_SSL_ENABLE(SysParamModuleEnum.EMAIL.getModule(), "sslEnable", "是否使用SSL安全连接"),
    PUZZLE_VERIFY(SysParamModuleEnum.VERIFY.getModule(), "puzzleVerify", "是否开启拼图验证"),
    S3_SERVICE(SysParamModuleEnum.STORAGE.getModule(), "s3Service", "s3服务,aliyun或aws"),
    PERSONAL_SPACE_CATALOG(SysParamModuleEnum.STORAGE.getModule(), "personalSpaceCatalog", "用户存储根目录"),
    PERSONAL_SPACE_CACHE_CATALOG(SysParamModuleEnum.STORAGE.getModule(), "personalSpaceCacheCatalog", "用户存储缓存根目录"),
    WORK_SPACE_CATALOG(SysParamModuleEnum.STORAGE.getModule(), "workSpaceCatalog", "工作空间根目录"),
    WORK_SPACE_CACHE_CATALOG(SysParamModuleEnum.STORAGE.getModule(), "workSpaceCacheCatalog", "工作空间缓存根目录"),
    PRODUCT_RELEASE_CATALOG(SysParamModuleEnum.PRODUCT.getModule(), "releaseCatalog", "产品软件发布根目录"),
    WECHAT_WEBSITE_SAAS_APP_ID(SysParamModuleEnum.WECHAT_WEBSITE.getModule(),"appId","appId"),
    WECHAT_WEBSITE_SAAS_APP_SECRET(SysParamModuleEnum.WECHAT_WEBSITE.getModule(),"appSecret","appSecret"),
    WECHAT_WEBSITE_SAAS_REDIRECT_URI(SysParamModuleEnum.WECHAT_WEBSITE.getModule(),"redirectUri","授权回调域"),
    ;
    private final String module;
    private final String key;
    private final String text;

    SysParamKeyEnum(String module, String key, String text) {
        this.module = module;
        this.key = key;
        this.text = text;
    }

    public String getModule() {
        return module;
    }

    public String getKey() {
        return key;
    }

    public String getText() {
        return text;
    }

    public static void assertValid(String module, String key) {
        SysParamKeyEnum instance = instance(module, key);
        Assert.notNull(instance, "系统参数未知：{module: {}, key: {}}", module, key);
    }

    public static SysParamKeyEnum instance(String module, String key) {
        for (SysParamKeyEnum instance : SysParamKeyEnum.values()) {
            if (Objects.equals(instance.getModule(), module)
                && Objects.equals(instance.getKey(), key)) {
                return instance;
            }
        }
        return null;
    }
}
